﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//
using PerceptiveMCAPI;
using PerceptiveMCAPI.Types;
using System.Data;
//

namespace PerceptiveMCAPI_Test
{
   public partial class show_campaignTemplates : System.Web.UI.UserControl
   {
      public void Display( campaignTemplatesOutput output )
      {
         this.Visible = true;
         lblCount.Text = output.result.Count.ToString();

         // ------------------------------------------------------------ 
         // manual format to get sections to display
         // ------------------------------------------------
         DataTable tbl = new DataTable( "Templates" );
         tbl.Columns.Add( "id" ); tbl.Columns.Add( "name" );
         tbl.Columns.Add( "layout" ); tbl.Columns.Add( "preview_image" );
         tbl.Columns.Add( "sections" );
         foreach ( campaignTemplatesResults template in output.result )
         {
            DataRow row = tbl.NewRow();
            row["id"] = template.id;
            row["name"] = template.name;
            row["layout"] = template.layout;
            row["preview_image"] = template.preview_image;
            row["sections"] = ApiHelper.MakeStringFromList( template.sections );
            tbl.Rows.Add( row );
         }
         gvTemplates.DataSource = tbl;
         gvTemplates.DataBind();
         // ------------------------------------------------------------ 
      }
   }
}